package com.aeroyun.macross.modular.countryside.controller;

import com.aeroyun.macross.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.aeroyun.macross.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.aeroyun.macross.modular.system.model.PeasantHousehold;
import com.aeroyun.macross.modular.countryside.service.IPeasantHouseholdService;

/**
 * 农户管理控制器
 *
 * @author fengshuonan
 * @Date 2018-08-17 14:09:29
 */
@Controller
@RequestMapping("/peasantHousehold")
public class PeasantHouseholdController extends BaseController {

    private String PREFIX = "/countryside/peasantHousehold/";

    @Autowired
    private IPeasantHouseholdService peasantHouseholdService;

    /**
     * 跳转到农户管理首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "peasantHousehold.html";
    }

    /**
     * 跳转到添加农户管理
     */
    @RequestMapping("/peasantHousehold_add")
    public String peasantHouseholdAdd() {
        return PREFIX + "peasantHousehold_add.html";
    }

    /**
     * 跳转到修改农户管理
     */
    @RequestMapping("/peasantHousehold_update/{peasantHouseholdId}")
    public String peasantHouseholdUpdate(@PathVariable Integer peasantHouseholdId, Model model) {
        PeasantHousehold peasantHousehold = peasantHouseholdService.selectById(peasantHouseholdId);
        model.addAttribute("item",peasantHousehold);
        LogObjectHolder.me().set(peasantHousehold);
        return PREFIX + "peasantHousehold_edit.html";
    }

    /**
     * 获取农户管理列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return peasantHouseholdService.selectList(null);
    }

    /**
     * 新增农户管理
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(PeasantHousehold peasantHousehold) {
        peasantHouseholdService.insert(peasantHousehold);
        return SUCCESS_TIP;
    }

    /**
     * 删除农户管理
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer peasantHouseholdId) {
        peasantHouseholdService.deleteById(peasantHouseholdId);
        return SUCCESS_TIP;
    }

    /**
     * 修改农户管理
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(PeasantHousehold peasantHousehold) {
        peasantHouseholdService.updateById(peasantHousehold);
        return SUCCESS_TIP;
    }

    /**
     * 农户管理详情
     */
    @RequestMapping(value = "/detail/{peasantHouseholdId}")
    @ResponseBody
    public Object detail(@PathVariable("peasantHouseholdId") Integer peasantHouseholdId) {
        return peasantHouseholdService.selectById(peasantHouseholdId);
    }
}
